<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!-- Modal transactionDetailModal-->
	<div id="transactionDetailModal" class="modal fade" role="dialog">
	  <div class="modal-dialog">	
	    <!-- Modal content-->
	    <div class="modal-content">
	      <div class="modal-header">
	        <button type="button" class="close" data-dismiss="modal">&times;</button>
	        <h4 class="modal-title">Transaction Information</h4>
	      </div>
	      <div class="modal-body">
	        <div id="transactionDetailModalContent">
	        	<h4>Transaction Info</h4>
	        	<table class="table table-bordered table-condensed table-striped">
	        		<tr>
				        <td>Transaction Id</td><td id="transactionIdTD">&nbsp;</td>
				    </tr>
				    <tr>
				        <td>Create Time</td><td id="transactionCreateTimeTD">&nbsp;</td>
				    </tr>
				    <tr>
				        <td>Status</td><td id="transactionStatusTD">&nbsp;</td>
				    </tr>
				    <tr>
				        <td>Type</td><td id="transactionTypeTD">&nbsp;</td>
			        </tr>
			    </table>
			    <br>
			    <div id="paymentInfoDIV" style="display:none">
			    <h4>Payment Info</h4>
	        	<table class="table table-bordered table-condensed table-striped">
	        		<tr>
				        <td class="text-center">Create By</td>
				        <td class="text-center">Request Time</td>
				        <td class="text-center">Alipay Pay Time</td>
				        <td class="text-center">Customer</td>
			        </tr>
		        	<tr>
				        <td class="text-center" id="paymentByTD">&nbsp;</td>
				        <td class="text-center" id="paymentRequestTimeTD">&nbsp;</td>
				        <td class="text-center" id="alipayPayTimeTD">&nbsp;</td>
				        <td class="text-center" id="alipayBuyerLoginIDTD">&nbsp;</td>
			        </tr>
			    </table>
			    <br>
			    </div>
			    <div id="cancelInfoDIV" style="display:none">
			    <h4>Cancel Info</h4>
	        	<table class="table table-bordered table-condensed table-striped">
	        		<tr>
				        <td class="text-center">Cancel By</td>
				        <td class="text-center">Request Time</td>
				        <td class="text-center">Alipay Cancel Time</td>
			        </tr>
		        	<tr>
				        <td class="text-center" id="cancelByTD">&nbsp;</td>
				        <td class="text-center" id="cancelRequestTimeTD">&nbsp;</td>
				        <td class="text-center" id="alipayCancelTimeTD">&nbsp;</td>
			        </tr>
			    </table>
			    <br>
			    </div>
			    <div id="reverseInfoDIV" style="display:none">
			    <h4>Reverse Info</h4>
	        	<table class="table table-bordered table-condensed table-striped">
	        		<tr>
				        <td class="text-center">Reverse By</td>
				        <td class="text-center">Request Time</td>
				        <td class="text-center">Alipay reverse Time</td>
			        </tr>
		        	<tr>
				        <td class="text-center" id="reverseByTD">&nbsp;</td>
				        <td class="text-center" id="reverseRequestTimeTD">&nbsp;</td>
				        <td class="text-center" id="alipayReverseTimeTD">&nbsp;</td>
			        </tr>
			    </table>
			    <br>
			    </div>
			    <div id="refundInfoDIV" style="display:none">
			    <h4>Refund Info</h4>
	        	<table class="table table-bordered table-condensed table-striped">
	        		<tr>
				        <td class="text-center">Refund By</td>
				        <td class="text-center">Request Time</td>
				        <td class="text-center">Alipay Refund Time</td>
			        </tr>
		        	<tr>
				        <td class="text-center" id="refundByTD">&nbsp;</td>
				        <td class="text-center" id="refundRequestTimeTD">&nbsp;</td>
				        <td class="text-center" id="alipayRefundTimeTD">&nbsp;</td>
			        </tr>
			    </table>
			    </div>
	        </div>
	      </div>
	      <div class="modal-footer">
	        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
	      </div>
	    </div>	
	  </div>
	</div>
	
	<script type="text/javascript">
	function showMTDetail(mtId){
		cleanUp();
		$.ajax({
			url: '<%=request.getContextPath()%>/bdQuery/mtQuery',
			dataType: "json",
			contentType: "application/json",
			data: {
				mtId: mtId,
			},
			success: function(data) {
				$("#transactionIdTD").text(data.mtId);
				$("#transactionStatusTD").text(data.status);
				$("#transactionTypeTD").text(data.type);
				$("#transactionCreateTimeTD").text(data.create_time);
				if(data.make_payment_by){
					$("#paymentByTD").text(data.make_payment_by);
					$("#paymentRequestTimeTD").text(data.payment_request_time);
					$("#alipayBuyerLoginIDTD").text(data.alipay_buyer_login_id);
					$("#alipayPayTimeTD").text(data.alipay_pay_time);
					$("#paymentInfoDIV").css("display","block");
				}
				if(data.cancel_by){
					$("#cancelByTD").text(data.cancel_by);
					$("#cancelRequestTimeTD").text(data.cancel_request_time);
					$("#alipayCancelTimeTD").text(data.alipay_cancel_time);
					$("#cancelInfoDIV").css("display","block");
				}
				if(data.refund_by){
					$("#refundByTD").text(data.refund_by);
					$("#refundRequestTimeTD").text(data.refund_request_time);
					$("#alipayRefundTimeTD").text(data.alipay_refund_time);
					$("#refundInfoDIV").css("display","block");
				}
				if(data.reverse_by){
					$("#reverseByTD").text(data.reverse_by);
					$("#reverseRequestTimeTD").text(data.reverse_request_time);
					$("#alipayReverseTimeTD").text(data.alipay_reverse_time);
					$("#reverseInfoDIV").css("display","block");
				}
				
				$("#transactionDetailModal").modal({
				  backdrop: 'static',
				  keyboard: false
				});
			},
			error:function(e, x, settings, exception) {
	            var message;
	            var statusErrorMap = {
	                '400' : "Server understood the request, but request content was invalid.",
	                '401' : "Unauthorized access.",
	                '403' : "Forbidden resource can't be accessed.",
	                '500' : "Internal server error.",
	                '503' : "Service unavailable."
	            };
	            if (x.status) {
	                message =statusErrorMap[x.status];
	                                if(!message){
	                                      message="Unknown Error \n.";
	                                  }
	            }else if(exception=='parsererror'){
	                message="Error.\nParsing JSON Request failed.";
	            }else if(exception=='timeout'){
	                message="Request Time out.";
	            }else if(exception=='abort'){
	                message="Request was aborted by the server";
	            }else {
	                message="Unknown Error \n.";
	            }
	            message = message + ", This is abnormal.Please contact support. Please use Home button to return home page.";
	            //alert(message);
	            $('#waitingModal').modal('hide');
	            $("#warningModalContent").text(message);
				$("#warningModal").modal();
			},
			type: 'GET'
		});
	}
	function cleanUp(){
		$("#transactionIdTD").text();
		$("#transactionStatusTD").text();
		$("#transactionTypeTD").text();
		$("#transactionCreateTimeTD").text();

		$("#paymentByTD").text();
		$("#paymentRequestTimeTD").text();
		$("#alipayBuyerLoginIDTD").text();
		$("#alipayPayTimeTD").text();
		$("#paymentInfoDIV").css("display","none");
		
		$("#cancelByTD").text();
		$("#cancelRequestTimeTD").text();
		$("#alipayCancelTimeTD").text();
		$("#cancelInfoDIV").css("display","none");
		
		$("#refundByTD").text();
		$("#refundRequestTimeTD").text();
		$("#alipayRefundTimeTD").text();
		$("#refundInfoDIV").css("display","none");
		
		$("#reverseByTD").text();
		$("#reverseRequestTimeTD").text();
		$("#alipayReverseTimeTD").text();
		$("#reverseInfoDIV").css("display","none");	
	}
	</script>